﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace Skylabs.Breeze
{
    public class TraceCacheEvent : EventArgs
    {
        public String Event { get; set; }
        public TraceCacheEvent(string eve)
        {
            Event = eve;
        }
        
    }
    public class CacheTraceListener : TraceListener
    {
        public List<String> Events { get; set; }
        public event EventHandler<TraceCacheEvent> OnEventAdd; 
        public CacheTraceListener()
        {
            Events = new List<string>();
        }
        public override void Write(string message)
        {
            lock (this)
            {
                Events.Add(message);
                if (OnEventAdd != null)
                    OnEventAdd.Invoke(this, new TraceCacheEvent(message));
            }
        }

        public override void WriteLine(string message)
        {
            lock (this)
            {
                Events.Add(message + "\n");
                if (OnEventAdd != null)
                    OnEventAdd.Invoke(this, new TraceCacheEvent(message + "\n"));
            }
        }
    }
}
